﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApp_Session
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                List<string> lst = new List<string>()
                {
                    "aaa",
                    "bbb",
                    "ccc"
                };



                foreach (var item in lst)
                {
                    Session[item] = new Random().NextDouble().ToString();
                    Thread.Sleep(100);
                }

                Response.Write("Session已加入完毕！<br/>");


                foreach (var item in lst)
                {
                    HttpCookie ck = new HttpCookie(item, new Random().Next().ToString());                   
                    ck.Expires = DateTime.Now.AddDays(30);
                    if (item == "bbb")
                    {
                        ck.Expires = DateTime.Now.AddSeconds(10);
                    }
                    Response.Cookies.Add(ck);
                    Thread.Sleep(100);
                }
                Response.Write("Cookie已加入完毕！");
            }

        }
    }
}